package factory.impl;

import factory.OperationFactory02;
import service.OperationService;
import service.impl.OperationAdd;
import service.impl.OperationDiv;
import service.impl.OperationMul;
import service.impl.OperationSub;

public class OperationFactory02Impl implements OperationFactory02 {
    private  final String[] operations;

    public OperationFactory02Impl(String [] operations){
        this.operations=operations;
    }
    @Override
    public OperationService createOperaction() {
        // 根据传入的操作类型创建相应的 OperationService 实例
        for (String operation : operations) {
            switch (operation) {
                case "add":
                    return new OperationAdd();
                case "sub":
                    return new OperationSub();
                case "mul":
                    return new OperationMul();
                case "div":
                    return new OperationDiv();
                case "mod":
                    return new OperationDiv();
                default:
                    throw new IllegalArgumentException("Unsupported operation: " + operation);
            }
        }
        throw new IllegalArgumentException("No valid operation provided");
    }
}
